package com.hvgroup.modules.sanic.web;


import com.hvgroup.modules.sanic.service.SeleniumService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/common")
@RequiredArgsConstructor
public class CommonChatController {

    private final SeleniumService seleniumService;

    @Value("${env:dev}")
    private String env;

    /**
     * 通用问答：获取搜索引擎第一个结果 URL
     */
    @PostMapping("/get_search_url")
    public String getBingSearchUrl(@RequestParam("query_str") String queryStr) {
        try {
            if ("test".equalsIgnoreCase(env)) {
                return seleniumService.getBingFirstHref(queryStr);
            } else {
                return seleniumService.getSearchResultsLinks(queryStr);
            }
        } catch (Exception e) {
            log.error("Error processing LLM output: {}", e.getMessage(), e);
//            throw new MyException(SysCodeEnum.C_9999);
        }
        return null;
    }
}